<template>
  <div class="login">
    <el-form :model="ruleForm" status-icon ref="ruleForm" class="demo-ruleForm">
  <h1>系统登录</h1>
  <!-- 用户名 -->
  <el-form-item >
    <el-input
    type="text"
    v-model="ruleForm.username"
    autocomplete="off"
    clearable
    placeholder="请输入用户名"
    prefix-icon="el-icon-user-solid"
    >
    </el-input>
  </el-form-item>
  <!-- 密码 -->
  <el-form-item >
    <el-input
    type="password"
    v-model="ruleForm.pwd"
    autocomplete="off"
    show-password
    placeholder="请输入密码"
    prefix-icon="el-icon-lock"
    >
    </el-input>
  </el-form-item>

  <el-form-item>
    <el-button type="primary" @click="submitForm">提交</el-button>
  </el-form-item>
</el-form>
  </div>
</template>

<script>
import { artLogin } from '@api'
import Cookie from 'js-cookie'
export default {
  data () {
    return {
      ruleForm: {
        username: '',
        pwd: ''
      }
    }
  },
  methods: {
    submitForm () {
      artLogin(this.ruleForm).then(res => {
        if (res.data.code === 200) {
          Cookie.set('token', res.data.data.token)
          Cookie.set('userInfo', res.data.data.userInfo)
          Cookie.set('role', res.data.data.role)
          this.$message({
            message: '登录成功',
            type: 'success',
            onClose: () => {
              this.$router.replace('/home')
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login{
  width: 100%;
  height: 100%;
  background-color:rgb(146, 183, 196) ;
  display: flex;
  justify-content: center;
  align-items: center;
  .el-form{
    h1{
      font-size: 30px;
      color: white;
      text-align: center;
      font-weight: 700;
      margin-bottom: 10px;
      letter-spacing:3px;
    }
    width: 300px;
    height: 170px;
    .el-button{
      width: 100%;
    }
  }
}
</style>
